// MailNoter - A capture tool for emails

// Copyright (C) 2009 - MailNoter

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#pragma once

#include <mapi.h>          // MAPI function defs

#include <vector>
#include <string>


typedef std::pair<std::string,std::string> TStrStrPair;
typedef std::vector<TStrStrPair> TStrStrVector;


class CMailMsg  
{
public:
	CMailMsg();
	virtual ~CMailMsg();

   CMailMsg& SetTo(std::string sAddress, std::string sName = "");

   CMailMsg& SetCc(std::string sAddress, std::string sName = "");

   CMailMsg& SetBc(std::string sAddress, std::string sName = "");

   CMailMsg& SetFrom(std::string sAddress, std::string sName = "");

   CMailMsg& SetSubject(std::string sSubject) { m_sSubject = sSubject; return *this;}

   CMailMsg& SetMessage(std::string sMessage) { m_sMessage = sMessage; return *this;}

   CMailMsg& AddAttachment(std::string sAttachment, std::string sTitle = "");

   BOOL Send();

protected:

   int MAPISend();

   BOOL Initialize();

   void Uninitialize();

   int cResolveName(LHANDLE m_lhSession, const char * lpszName, lpMapiRecipDesc *ppRecip);

   TStrStrVector  m_from;
   TStrStrVector  m_to;
   TStrStrVector  m_cc;
   TStrStrVector  m_bcc;
   TStrStrVector  m_attachments;
   std::string    m_sSubject;
   std::string    m_sMessage;

   HMODULE        m_hMapi;
   LPMAPILOGON    m_lpMapiLogon;
   LPMAPISENDMAIL m_lpMapiSendMail;
   LPMAPILOGOFF   m_lpMapiLogoff;
   LPMAPIRESOLVENAME m_lpMapiResolveName;
   LPMAPIFREEBUFFER m_lpMapiFreeBuffer;
   
   BOOL           m_bReady;
};
